<template>
  <div class="toast" v-show="isShow">
    {{message}}
  </div>
</template>

<script>
  export default {
    name: "Toast",
    data(){
      return {
        isShow: false,
        message: '默认消息'
      }
    },
    methods: {
      show(message='默认消息', duration=2000){
        console.log(message, duration)
        this.isShow = true;
        this.message = message;
        const timeId = setTimeout(()=>{
          this.isShow = false;
          this.message = '';
          clearTimeout(timeId)
        },duration)
      }
    }
  }
</script>

<style scoped>
  .toast{
    max-width: 80vw;
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 10px;
    background-color: rgba(75, 75, 75, 0.7);
    color: #fff;
    border-radius: 10px;

  }
</style>
